package com.water.camera.kt

import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.snap.base.ktx.exitAccountDialog
import com.snap.base.ktx.isChecking
import com.snap.base.ktx.isLogin
import com.snap.base.ktx.startAgreement
import com.snap.base.ktx.startFeedback
import com.snap.base.ktx.startPrivacy
import com.snap.common.main.BaseVM
import com.snap.base.util.BaseUtil
import com.snap.login.ktx.startLoginAct
import com.snap.util.appVerName
import com.snap.util.startAct
import kotlinx.coroutines.launch

class MeVM : BaseVM() {

    lateinit var actionAct: () -> FragmentActivity
    val isAudio = MutableLiveData<Boolean>().apply {
        value = BaseUtil.isChecking()
    }
    val versionName = MutableLiveData<String>().apply {
        value = "当前版本$appVerName"
    }

    fun clickAsk() = BaseUtil.startFeedback()

    fun startAgreement() = BaseUtil.startAgreement()

    fun startPrivacy() = BaseUtil.startPrivacy()

    lateinit var actionUpdate: suspend () -> Unit

    fun clickBuy() {
        startAct(BuyAct::class.java)
    }

    fun clickVersion() {
        viewModelScope.launch {
            actionUpdate.invoke()
        }
    }

    fun clickEmail() {
        BaseUtil.copyEmail("hfldygkj@163.com")
    }

    fun clickExitAccount() {
        BaseUtil.exitAccountDialog(actionAct.invoke(), true)
    }

    fun clickClearAccount() {
        BaseUtil.exitAccountDialog(actionAct.invoke(), false)
    }

    fun clickLogin() {
        if (BaseUtil.isLogin() || isAudio.value == true) return
        BaseUtil.startLoginAct(false, firstColor = "#FFF4E6", goneQQ = true)
    }

}